package 手写ArraryList集合;

/**
 * @Gather:云尚学Java
 * 面向对象-接口-面向接口编程
 *
 * 解耦
 */
public class Demo {
    public static void main(String[] args) {
        //List<Integer> list=new ArrayList<Interger>():
        //1.构建自己手写的ArrayList集合
        MyList<String> myList=new MyArrayList<String>();
        //2.向集合中添加元素
        myList.add("A");
        //myList.add("ZZ");
        myList.add("B");
        myList.add("C");
        myList.add("D");
        myList.add("E");
        myList.add("F");
        System.out.println("===实际存储元素的个数："+myList.size());
        System.out.println("===依据索引获取该索引位置的元素");
        System.out.println(myList.get(0));//A
        System.out.println(myList.get(1));//B
        System.out.println(myList.get(2));//C


        System.out.println("依据索引修改该索引位置的元素");
        String oldValue=myList.set(0,"AA");
        System.out.println(oldValue+"-"+myList.get(0));//A-AA


        System.out.println("===向指定索引位置新增元素");
        myList.add(1,"zz");
        System.out.println(myList.get(1));//ZZ
        System.out.println(myList.get(2));//B

        System.out.println("判断集合中是否包含指定的元素");
        System.out.println(myList.contains("AA"));//true


        System.out.println("===依据指定的字符串返回该字符串在集合中的索引");
        System.out.println(myList.indexOf("B"));//2

        System.out.println("删除指定的元素");
        myList.remove("ZZ");
        System.out.println(myList.get(2));//B

        System.out.println("判断集合元素是否为空");
        System.out.println(myList.isEmpty());//false
    }
}
